//
//  MarketView.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/2/5.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "MarketView.h"
#import "SelectionConsultationViewController.h"
#import "ContractListViewController.h"
@implementation MarketView

-(void)creatView{
    self.backgroundColor=_LightGrey;
    
    UIImageView *shopImage=[UIImageView new];
    [self addSubview:shopImage];
    [shopImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT+10);
        make.height.mas_equalTo(200);
    }];
    shopImage.image=[UIImage imageNamed:@"法律商城背景图"];

    UILabel *shopLabel=[UILabel new];
    [shopImage addSubview:shopLabel];
    [shopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.mas_equalTo(-30);
        make.right.mas_equalTo(-100);
    }];
    shopLabel.textColor=[UIColor whiteColor];
    shopLabel.font=[UIFont systemFontOfSize:18];
    shopLabel.text=@"法律商城";

    UILabel *shopLabel2=[UILabel new];
    [shopImage addSubview:shopLabel2];
    [shopLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-80);
    }];
    shopLabel2.textColor=[UIColor whiteColor];
    shopLabel2.font=[UIFont systemFontOfSize:14];
    shopLabel2.text=@"精选多个咨询案例和文书模版，供你参考~~";

    UIImageView *shopImage2=[UIImageView new];
    [shopImage addSubview:shopImage2];
    [shopImage2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(65);
        make.centerY.mas_equalTo(0);
    }];
    shopImage2.image=[UIImage imageNamed:@"法律商城图标"];

    
    UIView *topView=[UIView new];
    [self addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(shopImage);
        make.top.mas_equalTo(shopImage.mas_bottom);
        make.height.mas_equalTo(150);
    }];
    topView.layer.cornerRadius=5;
    topView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *zixun=[UIImageView new];
    [topView addSubview:zixun];
    [zixun mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(15);
        make.height.mas_equalTo(130);
        make.width.mas_equalTo(_mainW/2-20);
    }];
    zixun.userInteractionEnabled=YES;
    UITapGestureRecognizer *Market = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToJingXuan:)];
    [zixun addGestureRecognizer:Market];
    zixun.backgroundColor=ColorWithRGB(78, 191, 245);
    zixun.layer.cornerRadius=5;
    
    
    UILabel *label=[UILabel new];
    [zixun addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
    }];
    label.text=@"精选咨询";
    label.font=[UIFont systemFontOfSize:18];
    label.textColor=[UIColor whiteColor];
    
    UILabel *label2=[UILabel new];
    [zixun addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(label.mas_bottom).mas_equalTo(10);
    }];
    label2.text=@"JINGXUANZIXUN";
    label2.font=[UIFont systemFontOfSize:18];
    label2.textColor=[UIColor whiteColor];
    
    
    UIImageView *imageView2=[UIImageView new];
    [zixun addSubview:imageView2];
    [imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(50);
    }];
    imageView2.image=[UIImage imageNamed:@"图标"];
    
    
    UIImageView *xiaZai=[UIImageView new];
    [topView addSubview:xiaZai];
    [xiaZai mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(130);
        make.width.mas_equalTo(_mainW/2-20);
    }];
    
    NSDictionary *dic=_tableArr[0];

    xiaZai.userInteractionEnabled=YES;
    UITapGestureRecognizer *HeTong = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToHeTong:)];
    [xiaZai addGestureRecognizer:HeTong];
    
    NSString *gtype_color=[dic objectForKey:@"gtype_color"];
    xiaZai.backgroundColor=[self colorWithGBK:gtype_color alpha:1];
    xiaZai.layer.cornerRadius=5;
    UILabel *label3=[UILabel new];
    [xiaZai addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
    }];
    label3.text=[dic objectForKey:@"gtype_name"];
    label3.font=[UIFont systemFontOfSize:18];
    label3.textColor=[UIColor whiteColor];
    
    UILabel *label4=[UILabel new];
    [xiaZai addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(label.mas_bottom).mas_equalTo(10);
    }];
    label4.text=[dic objectForKey:@"gtype_ename"];
    label4.font=[UIFont systemFontOfSize:18];
    label4.textColor=[UIColor whiteColor];
    
    
    UIImageView *imageView3=[UIImageView new];
    [xiaZai addSubview:imageView3];
    [imageView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(50);
    }];
    NSString *gtype_image=[dic objectForKey:@"gtype_image"];
    NSURL *rul=[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_addressUrl,gtype_image]];
    [imageView3 sd_setImageWithURL:rul];
   

    
    
}
-(void)pushToJingXuan:(UITapGestureRecognizer *)tap{
    SelectionConsultationViewController *select=[[SelectionConsultationViewController  alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:select];
    
}
-(void)pushToHeTong:(UITapGestureRecognizer *)tap{
    ContractListViewController *select=[[ContractListViewController  alloc] init];
    select.dic=_tableArr[0];
    [ZQTools pushNextViewController:self.viewController andRootController:select];
    
}

-(UIColor *)colorWithGBK:(NSString *)GBK alpha:(float)alpha
{
    unsigned int red,green,blue;
    NSRange range;
    range.length = 2;
    
    if ([GBK rangeOfString:@"#"].length == 0) {
        range.location = 0;
        [[NSScanner scannerWithString:[GBK substringWithRange:range]] scanHexInt:&red];
        
        range.location = 2;
        [[NSScanner scannerWithString:[GBK substringWithRange:range]] scanHexInt:&green];
        
        range.location = 4;
        [[NSScanner scannerWithString:[GBK substringWithRange:range]] scanHexInt:&blue];
    }else{
        range.location = 1;
        [[NSScanner scannerWithString:[GBK substringWithRange:range]] scanHexInt:&red];
        
        range.location = 3;
        [[NSScanner scannerWithString:[GBK substringWithRange:range]] scanHexInt:&green];
        
        range.location = 5;
        [[NSScanner scannerWithString:[GBK substringWithRange:range]] scanHexInt:&blue];
    }
    return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:alpha];
}
@end
